<?php defined('SYSPATH') OR die('No direct access allowed.');

class Page_Controller extends Home_Controller {
	public function __construct(){
		parent::__construct();
		

	}
	public function index ($i_Active=0, $i_Subactive=0, $i_Register=0){
		$this->template = new View($this->template);
		$this->_set_content($i_Active, $i_Subactive);
		
		if (!$this->auth->logged_in()){
			$this->template->register = 'Register';
			$this->template->register_link = '/register';
			$this->template->login = 'login';
			$this->template->login_link = '/login';
		}
		//@todo: zajebac jakos inaczej menu od  rejestracji i logowania. o. 
		$this->template->render(TRUE);
	}
	
	public function admin(){
		if ($this->auth->logged_in()){
			url::redirect ('/page');
		}
		
		$this->template = new View($this->template);
		$this->_set_content(2, 0);
		
		$this->template->form_Login = new View('t_form_login');
		//$this->template->title = 'Login';
		$this->template->render(TRUE);
		//$this->template->form_login->render(TRUE);
	}
	
	private function _set_content($i_Active, $i_Subactive){
		$m_Content = new Content_Model;
		
		$m_Content->get_content($i_Active, $i_Subactive);
		
		
		$this->template->title = $m_Content->a_Content['title'];
		if ($m_Content->a_Content['main_menu']) $this->template->main_menu = $m_Content->a_Content['main_menu'];
		if ($m_Content->a_Content['submenu']) $this->template->sub_menu = $m_Content->a_Content['submenu'];
		if ($m_Content->a_Content['submenu']) $this->template->sub_title = $m_Content->a_Content['submenu'][$i_Subactive]['name'];
	}
	
	public function logine(){
		if ($this->auth->logged_in()){
			url::redirect ('/page');
		}
		
		$m_FormLogin = new Form_Login_Model;
		
		$a_FormLoginData = $m_FormLogin->receive_data();
		
		
		if (isset($a_FormLoginData['info'])){
			//url::redirect('/register/success');
			$this->template = new View($this->template);
			$this->_set_content(2,0);
			$this->template->form_Login = $a_FormLoginData['info'];
			$this->template->render(TRUE);
		}
		else {
			$this->template = new View($this->template);
			$this->_set_content(2, 0);
			$this->template->form_Login = new View('t_form_login');
			
			$this->template->form_Login->o_Post = $a_FormLoginData->as_array();
			
			$this->template->render(TRUE);
		}
	}
}
?>